package com.ctvit.framework.excel;

import bsh.EvalError;
import bsh.Interpreter;

/**
 * Excel导出数据上下文.
 * 
 * @author WangChen
 * @author Q-Wang
 */
public class PrintContext {

	private Interpreter interpreter = new Interpreter();
	private int pageCount = 1; // sheet 数量
	protected int currentPage = 0; // 当前处理的sheet页的index（从0开始）
	private String sheetLabel = "Sheet1"; // 当前处理的sheet页的标签

	public PrintContext() {
		super();

	}

	public PrintContext(int pageCount) {
		super();
		this.pageCount = pageCount;
	}

	public String getSheetLabel() {
		return sheetLabel;
	}

	public void setSheetLabel(String sheetLabel) {
		this.sheetLabel = sheetLabel;
	}

	public int getPageCount() {
		return pageCount;
	}

	public void setPageCount(int pageCount) {
		this.pageCount = pageCount;
	}

	public int getCurrentPage() {
		return currentPage;
	}

	/**
	 * 添加数据.
	 * 
	 * @param name
	 * @param value
	 */
	public void addAttribute(String name, Object value) {
		try {
			interpreter.set(name, value);
		} catch (EvalError e) {
			e.printStackTrace();
		}
	}

	/**
	 * 导出框架用.
	 * 
	 * @param script
	 * @return
	 */
	Object getValue(String script) {
		Object result = null;
		try {
			result = interpreter.eval(script);
		} catch (EvalError e) {
			e.printStackTrace();
		}
		return result;
	}
}